package demo.practice.stack;

public class P1381 {
    class CustomStack {
        int[] stack;
        int[] add;
        int top;

        public CustomStack(int maxSize) {
            stack = new int[maxSize];
            add = new int[maxSize];
            top = -1;
        }

        public void push(int x) {
            if (top != stack.length - 1) {
                ++top;
                stack[top] = x;
            }
        }

        public int pop() {
            if (top == -1) {
                return -1;
            }
            int ret = stack[top] + add[top];
            if (top != 0) {
                add[top - 1] += add[top];
            }
            add[top] = 0;
            --top;
            return ret;
        }

        public void increment(int k, int val) {
            int limit = Math.min(k - 1, top);
            if (limit >= 0) {
                add[limit] += val;
            }
        }
    }


}
class CustomStack{

    int size;
    int [] data;
    int pindex; //指针


    public CustomStack(int maxSize) {
        size=maxSize;
        data= new int[size];
        pindex=0;
    }

    public void push(int x) {
        if (pindex<size)
            data[pindex++]=x;
    }

    public int pop() {
        return pindex>0? data[--pindex] :-1;
    }

    public void increment(int k, int val) {
        for(int i=0;i<k&& i<size;i++){
            data[i]+=val;
        }
    }
}
